package genedit.controller.interfaceActions;

import genedit.controller.AlignCommand;
import genedit.model.Workspace;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;

/**
 * Akcija zadužena za poravnanje svih selektovanih elemenata po levoj ivici.
 * 
 * @author Nikola
 * @version 1.0 15/12/13
 */
public class GAlignLeft extends AbstractAction {

	private static final long serialVersionUID = 1L;

	private static GAlignLeft instance = null;

	public static GAlignLeft getInstance() {
		if (instance == null)
			instance = new GAlignLeft();
		return instance;
	}

	private GAlignLeft() {
		putValue(NAME, "Align left");
		putValue(SHORT_DESCRIPTION, "Align left");
		putValue(SMALL_ICON, new ImageIcon("resources/icons/alignLeft.png"));
		putValue(MNEMONIC_KEY, KeyEvent.VK_L);
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control L"));
	}

	/**
	 * Akcija kreira odgovarajuću komandu poravnanja i postavlja joj potrebne
	 * parametre, nakon čega je šalje na izvršavanje.
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		if (Workspace.getInstance().getActiveDocument() == null
				|| Workspace.getInstance().getActiveDocument().getModel().getSelectedElements()
						.isEmpty())
			return;

		AlignCommand align = new AlignCommand(true, 0);
		align.setDocument(Workspace.getInstance().getActiveDocument());
		align.setElements(Workspace.getInstance().getActiveDocument().getModel()
				.getSelectedElements());

		Workspace.getInstance().getActiveDocument().getModel().getInvoker().executeCommand(align);
	}

}
